package com.xgimi.mosby;

import android.support.annotation.NonNull;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.hannesdorfmann.mosby.mvp.MvpActivity;
import com.xgimi.mosby.presenter.LoginPresenter;
import com.xgimi.mosby.view.LoginView;

public class MainActivity extends MvpActivity<LoginView, LoginPresenter> implements LoginView, View.OnClickListener {

    private LoginPresenter mLoginPresenter;
    private Button mLoginBt;
    private TextView mLoginTv;
    private EditText mSsidEt, mPwdEt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mLoginBt = findViewById(R.id.loginbt);
        mLoginTv = findViewById(R.id.logininfotv);
        mPwdEt = findViewById(R.id.pwdet);
        mSsidEt = findViewById(R.id.ssidet);
        mLoginBt.setOnClickListener(this);
    }

    @NonNull
    @Override
    public LoginPresenter createPresenter() {
        if (mLoginPresenter == null) {
            mLoginPresenter = new LoginPresenter();
        }
        return mLoginPresenter;
    }

    @Override
    public void onSuccessView(String ssid, String pwd) {
        mLoginTv.setText("name---" + ssid + "----" + "pwd---" + pwd);
    }

    @Override
    public void onError(int code) {
        mLoginTv.setText("ErrorCode" + code);
    }

    @Override
    public void onClick(View v) {
        mLoginPresenter.loginl(mSsidEt.getText().toString(), mPwdEt.getText().toString());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mLoginPresenter.onCleanListener();
    }
}
